package com.zjmzxfzhl.modules.app.service.impl;

import com.zjmzxfzhl.modules.app.entity.*;
import com.zjmzxfzhl.modules.app.form.AppGitVo;
import com.zjmzxfzhl.modules.app.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zjmzxfzhl.common.core.base.BaseServiceImpl;
import com.zjmzxfzhl.modules.app.mapper.AppGitMapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service
 * 
 * @author 张森荣
 */
@Service
public class AppGitServiceImpl extends BaseServiceImpl<AppGitMapper, AppGit>
        implements AppGitService {
    @Autowired
    private AppProjService appProjService;
    @Autowired
    private AppProjGitService appProjGitService;

    @Override
    public IPage<AppGit> list(IPage<AppGit> page, AppGitVo appGitVo) {
        return page.setRecords(baseMapper.list(page, appGitVo));
    }
    /**
     * 新增项目，自动计算机构级别、机构级次码、是否叶子
     *
     * @param appGit
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AppGit saveAppGit(AppGit appGit,String projId) {
        AppProj appProj = appProjService.getById(projId);
        if (appProj == null) {
            return null;
        }
        this.save(appGit);
        appGit=this.getById(appGit.getGitId());
        if(appGit==null){
            return null;
        }
        AppProjGit appProjGit=new AppProjGit();
        appProjGit.setGitId(appGit.getGitId());
        appProjGit.setProjId(projId);
        appProjGitService.save(appProjGit);
        return appGit;
    }
}
